package ar.com.candoit.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ar.com.candoit.beans.Adress;


@Repository()
public class AdressDaoImpl implements AdressDao {

	@Autowired
	private SessionFactory sessionFactory;

	public void saveAdress(Adress adress) {
		sessionFactory.getCurrentSession().save(adress);
	}

	@SuppressWarnings("unchecked")
	public List<Adress> listAdress() {
		return sessionFactory.getCurrentSession().createQuery("from Adress").list();
	}

	public void removeAdress(Integer id) {
		Adress a = (Adress) sessionFactory.getCurrentSession().load(Adress.class, id);
		if (null != a) {
			sessionFactory.getCurrentSession().delete(a);
		}
	}

	@Override
	public Adress get(long adressid) {		
		return (Adress) sessionFactory.getCurrentSession().load(Adress.class, adressid);
	}
}
